<%@page import="java.math.BigDecimal,com.b2c.ftysys.view.application.*"%>
<%@ page language="java" import="com.b2c.ftysys.domain.BaseWord" contentType="text/html;charset=UTF-8"%>
<%@page import="java.util.*;"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>Word</title>
		  <meta http-equiv="pragma" content="no-cache">
          <meta http-equiv="cache-control" content="no-cache">
          <meta  http-equiv="pics-label" content="no-cache">
	</head>
	<body>
		<%
      response.setCharacterEncoding("UTF-8");
      response.setContentType("application/msword;charset=UTF-8");
      String type = request.getParameter("submit");
      //boolean flag = false;
      //List<baseWord> wordList = new ArrayList<baseWord>();

      if("convert".equals(type)){
        String fileName = request.getParameter("upFile");
        FileConvert con = new FileConvert();
        try{
        List<BaseWord> valueList = con.readExcelByPOI(fileName,"0");
        int num = valueList.size();
        //System.out.println("valueList Size:"+num);
        int i=1;
        String tempDiscpt="";
        int allNum = valueList.get(num-1).getNum();
        //System.out.println("allNum:"+allNum);
        valueList.remove(num-1);
        
        for (BaseWord word : valueList) {
        	String goodsId = word.getGoodsID().substring(3,8);
        	//System.out.println("goodsId:"+goodsId);
        	String pre = word.getGoodsID().substring(0,3);
        	String end = word.getGoodsID().substring(8);
           out.println("<table align='center' border='1' cellspacing='0' cellpadding='0' bordercolor='#000000'>");
           out.println("<tr><td width='157' valign='middle'>条码:"+word.getOrderID()+"</td>");
           out.println("<td width='168' valign='middle'>SKU号:"+pre+"<font color='blue'>"+goodsId+"</font>"+end+"</td>");
           out.println("<td width='120' valign='middle'>采购单号:"+word.getStockID()+"</td>");
           out.println("<td width='111' valign='middle'>供应商:0273</td></tr>");
           
           tempDiscpt = word.getDescription();
           if(tempDiscpt!=null && tempDiscpt.length()>0){
           if(tempDiscpt.indexOf("Belt Color=")>0){
              out.print("<tr><td colspan='2' width='325' valign='middle'>颜色:"+tempDiscpt.substring(tempDiscpt.indexOf("=")+1,tempDiscpt.indexOf(",")));
              out.println(" ,腰带颜色:"+tempDiscpt.substring((tempDiscpt.indexOf("Belt Color=")+11), tempDiscpt.indexOf(",",tempDiscpt.indexOf("Belt Color="))>0?tempDiscpt.indexOf(",",tempDiscpt.indexOf("Belt Color=")):tempDiscpt.length()));

              out.println("</td>");
              out.println("<td colspan='2' width='231' valign='middle'>数量:总"+allNum+"件,第");
              if(word.getNum()==1)
                  out.print(i);
                else if(word.getNum()>1){
                  out.print(i+"～"+(i+word.getNum()-1));
                  i+=(word.getNum()-1);
                }
              //out.print(i);
              out.print("件</td></tr>");
              out.println("<tr><td width='556' valign='middle' colspan='4'>尺寸:"+tempDiscpt.substring(tempDiscpt.indexOf(",")+1, tempDiscpt.indexOf("Belt Color=")-1)+" "+tempDiscpt.substring(tempDiscpt.indexOf(",",tempDiscpt.indexOf("Belt Color="))>0?tempDiscpt.indexOf(",",tempDiscpt.indexOf("Belt Color=")):tempDiscpt.length())+"</td>");
           }else {
              out.print("<tr><td colspan='2' width='325' valign='middle'>颜色:"+tempDiscpt.substring(tempDiscpt.indexOf("=")+1,tempDiscpt.indexOf(",")));
              out.println("</td>");
              
              out.println("<td colspan='2' width='231' valign='middle'>数量:总"+allNum+"件,第");
              if(word.getNum()==1)
                out.print(i);
              else if(word.getNum()>1){
                out.print(i+"～"+(i+word.getNum()-1));
                i+=(word.getNum()-1);
              }
              out.print("件</td></tr>");
              
              out.println("<tr><td width='556' valign='middle' colspan='4'>尺寸:"+tempDiscpt.substring(tempDiscpt.indexOf(",")+1)+"</td>");
           }
           }else{
        	   out.print("<tr><td colspan='2' width='325' valign='middle'>颜色:</td>");
               out.println("<td colspan='2' width='231' valign='middle'>数量:总"+allNum+"件,第");
               if(word.getNum()==1)
                   out.print(i);
                 else if(word.getNum()>1){
                   out.print(i+"～"+(i+word.getNum()-1));
                   i+=(word.getNum()-1);
                 }
               out.print("件</td></tr>");
               out.println("<tr><td width='556' valign='middle' colspan='4'>尺寸:</td>");
            
           }
           out.println("<tr><td colspan='2' width='325' valign='middle' >面料:");
           out.print(word.getCloth()!=null?word.getCloth():" ");
           out.println("</td>");     
           
           out.println("<td colspan='2' width='231' valign='middle' >价格:");
           out.print(word.getPrice().equals(BigDecimal.ZERO)?"0.00":word.getPrice());
           out.println("</td></tr>"); 
           
           out.println("<tr><td colspan='2' width='325' valign='middle'>下单日期:"+word.getStockDate()+"</td>");
           out.println("<td colspan='2' width='231' valign='middle'>发货日期:"+word.getDeliveryDate()+"</td></tr>");
           
           out.println("</table>");
           out.newLine();
           out.println("<p>");
           out.println("<br />");
           out.println("</p>");
           
           List<String> picName = word.getPicNames();
            for(int j=0; j<picName.size(); j++){
               out.print("<img src='file:///D:/tomcat/webapps/baseWeb/img/"+picName.get(j)+"' align='middle' border='0' >");
           }
           out.newLine();
           out.newLine();
           out.println("<p>");
           out.println("<br />");
           out.println("</p>");
           i++;
        }
        }catch(java.lang.NumberFormatException e){
           out.println("上传时异常");
           out.println(e);
           out.println("出错啦！");
        }
      }
      else{
         System.out.println("异常");
         out.println("请正确输入！");
      }
     %>
	</body>
</html>
